<!DOCTYPE html>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<c:set var="contextPath" value="${pageContext.request.contextPath}" />
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>利锋客户查询</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<meta content="width=device-width, initial-scale=1" name="viewport">
<link rel="stylesheet" type="text/css" href="${contextPath}/css/bootstrap.min.css" />
<link rel="stylesheet" type="text/css" href="${contextPath}/css/bootstrap-theme.min.css" />
<link rel="stylesheet" type="text/css" href="${contextPath}/css/bootstrap-datetimepicker.min.css" />
<link href="${contextPath}/css/jquery-ui.min.css" rel="stylesheet">
<link href="${contextPath}/css/jquery-ui.theme.min.css" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="${contextPath}/css/public.css">
<script type="text/javascript" src="${contextPath}/js/jquery.min.js"></script>
<script type="text/javascript" src="${contextPath}/js/bootstrap.min.js"></script>
<script type="text/javascript" src="${contextPath}/js/common.js"></script>
<script type="text/javascript" src="${contextPath}/js/bootstrap-datetimepicker.min.js"></script>
<script type="text/javascript" src="${contextPath}/js/locales/bootstrap-datetimepicker.zh-CN.js"></script>
<style type="text/css">
#showcount {
	padding-right: 30px;
}

#showcount span {
	padding-left: 30px;
}
</style>
</head>
<body>
	<%@ include file="../nav.jsp"%>
	<div class="container">
		<div class="panel panel-default">
			<div class="panel-heading">
				<input type="text" class="hidden" value="${requestScope.customerId}" id="customerId">
				<div style="line-height: 34px; float: left; font-weight: bold;">订单管理</div>
				<div style="float: right;">
					<span id="showcount"></span>
					<button type="button" id="searchBtn" class="btn btn-success">查询</button>
					<c:if test="${requestScope.customerId!=null}">
							<button type="button" class="btn btn-info" id="add" onclick="javascript:addBtn('${requestScope.customerId}');">新建订单</button>
					</c:if>
				</div>
				<div style="clear: both;"></div>
			</div>
			<div class="panel-body">
				<div class="form-group">
					<div class="form-inline">
						<div class="input-group">
							<div class="input-group-addon" style="font-weight: bold;">客户名称</div>
							<input class="form-control" id="name" type="text" placeholder="客户名称">
						</div>
						<div class="input-group">
							<div class="input-group-addon" style="font-weight: bold;">订单编号</div>
							<input class="form-control" id="orderNumber" type="text" placeholder="订单号">
						</div>
						<div class="input-group">
							<div class="input-group-addon" style="font-weight: bold;">订单时间</div>
							<input class="form-control form_date" data-date-format="yyyy-mm-dd" id="createTime" type="text" placeholder="订单时间">
						</div>
						<div class="input-group">
							<!-- 订单状态 -->
							<div class="input-group-addon" style="font-weight: bold;">订单状态</div>
							<select class="form-control" id="status" name="status">
								<option value="" selected="selected">全部</option>
								<option value="新单">新单</option>
								<option value="收单">收单</option>
							</select>
						</div>
						<div class="input-group">
							<!-- 货款状态 -->
							<div class="input-group-addon" style="font-weight: bold;">货款状态</div>
							<select class="form-control" id="paymentStatus" name="paymentStatus">
								<option value="" selected="selected">全部</option>
								<option value="欠款">欠款</option>
								<option value="全款">全款</option>
								<option value="免除">免除</option>
								<option value="坏账">坏账</option>
								<option value="代收">代收</option>
								<option value="已付">已付</option>
							</select>
						</div>
					</div>
				</div>
				<div class="table-responsive">
					<table class="table table-striped table-bordered table-hover">
						<thead>
							<tr>
								<th>序号</th>
								<th>客户名称</th>
								<th>状态</th>
								<th>订单编号</th>
								<th>订单日期</th>
								<th>送货地址</th>
								<th>货站卡号</th>
								<th>数量</th>
								<th>合计</th>
								<th>已支付款</th>
								<th>未支付款</th>
								<th>税率</th>
								<th>货款状态</th>
								<th>产品列表</th>
							</tr>
						</thead>
						<tbody></tbody>
					</table>
				</div>
				<ul class="pagination"></ul>
			</div>
		</div>
	</div>
	<!-- 删除模态框（Modal） -->
	<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
					<h4 class="modal-title">重要提示</h4>
				</div>
				<div class="modal-body">确定要删除该条数据？</div>
				<div class="modal-footer">
					<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
					<button type="button" class="btn btn-primary" id="deleteButton">删除</button>
				</div>
			</div>
			<!-- /.modal-content -->
		</div>
		<!-- /.modal -->
	</div>

	<script type="text/javascript">
		var addBtn = function(id) {
			var url = "${contextPath}/security/addOrder?customerId=" + id;
			window.open(url, "_top");
			//location.href=;
		}
		var utDropdownOpen = false;
		var nowUserType = 4;
		var nowPage = 0;
		var userNameCondition = "";
		var month = 0;
		var taskUpload = 2;
		var year = 0;
		var userId = 0;
		var pageTotal = 1;
		var deleteUserId = null;
		$(document).ready(function() {
			$('.form_date').datetimepicker({
				language : 'zh-CN',
				linkField : "salesTime",
				endDate : new Date(),
				initialDate : new Date(),
				weekStart : 0,
				todayBtn : 1,
				autoclose : 1,
				startView : 2,
				minView : 2
			});
			$('.form_dater').datetimepicker('show');

			$("#close").click(function() {
				window.close();
			});
			//$("#marriage-date").datepicker();
			chooseUserType(1);
			/*--------------------------------------点击查询按钮-------------------------------------------------------*/
			$("#searchBtn").click(function() {
				chooseUserType(1);
			});
			getProduct = function(id) {
				var url = "${contextPath}/security/product?orderNumber=" + id;
				window.open(url, "_top");
			}
			getPrint = function(id) {
				var url = "${contextPath}/security/print?orderNumber=" + id;
				window.open(url, "_top");
			}
			update = function(id) {
				var url = "${contextPath}/security/updateOrder?orderNumber=" + id;
				window.open(url, "_top");
			};
			delBtn = function(id) {
				deleteUserId = id;
				$("#myModal").modal('show');
			};
			/*--------------------------------------点击更改用户状态-------------------------------------------------------*/
			addProduct = function(id) {
				var url = "${contextPath}/security/addProduct?customerId=" + id;
				window.open(url, "_top");
			};
			findThisCustomerIdOrders = function(id) {
				var url = "${contextPath}/security/order?customerId=" + id;
				window.open(url, "_top");
			}
			/*--------------------------------------删除-------------------------------------------------------*/
			$("#deleteButton").click(function() {
				if (deleteUserId != null) {
					$.ajax({
						type : 'POST',
						data : {
							"id" : deleteUserId
						},
						url : '${contextPath}/security/deleteOrder',
						dataType : 'json',
						success : function(data) {
							chooseUserType(1);
							$("#myModal").modal('hide');
							//alert(data.message);
						}
					});
				}
			});

			$("#myModal").on('hide.bs.modal', function() {
				deleteUserId = null;
			});
			/*--------------------------------------更改用户状态-------------------------------------------------------*/
			$("#batchImportBtn").click(function() {
				//$("#import-iframe").attr("src","/ps/security/import");
				$("#import-dialog").modal('show');
			});
		});

		/*--------------------------------------加载页面-------------------------------------------------------*/
		chooseUserType = function(pageNum) {
			var name = $("#name").val();
			var orderNumber = $("#orderNumber").val();
			var createTime = $("#createTime").val();
			var status = $("#status").val();
			var paymentStatus = $("#paymentStatus").val();
			//var woman = $("#woman").val();
			//var date = $("#marriage-date").val();
			var customerId = $("#customerId").val();
			$.ajax({
				type : 'POST',
				data : {
					"page" : pageNum,
					"name" : name,
					"orderNumber" : orderNumber,
					"createTime" : createTime,
					"status" : status,
					"paymentStatus" : paymentStatus,
					"customerId" : customerId
				},
				url : '${contextPath}/security/order',
				dataType : 'json',
				success : function(data) {
					$("tbody").empty();
					if (data.list == "") {
						$("tbody").empty();
						$("tbody").append("<tr class='text-danger'><td colspan='13'>未查询到相关数据</td></tr>");
						//alert("未查询到相关信息！");
					} else {
						$.each(data.list, function(i, item) {
							$("tbody").append(
									"<tr>" + "<td>" + (i + 1) + "</td>" + "<td><a href='javascript:findThisCustomerIdOrders(" + item.customerid + ")'>" + item.name + "</a></td>" + "<td>"
											+ item.status + "</td>" + "<td><a href='javascript:update(" + item.ordernumber + ")'>" + item.ordernumber + "</a></td>" + "<td>" + item.orderCreateTime
											+ "</td>" + "<td>" + item.address + "</td>" + "<td>" + item.freightstationcard + "</td>" + "<td>" + item.number + "</td>" + "<td>" + item.totalStr
											+ "</td>" + "<td>" + item.paidStr + "</td>" + "<td>" + item.payableStr + "</td>" + "<td>" + item.tax + "%</td>" + "<td>" + item.paymentstatus + "</td>"
											+ "<td><a href='javascript:getProduct(\"" + item.ordernumber + "\")'>产品列表</a> </td>" + "</tr>");

						});
						//===================统计
						$("#showcount").empty();
						$("#showcount").append("<span>订单数：" + data.count.number + "</span>");
						$("#showcount").append("<span>总金额：" + data.count.totalStr + "</span>");
						$("#showcount").append("<span>已付金额：" + data.count.paidStr + "</span>");
						$("#showcount").append("<span>应收金额：" + data.count.payable + "</span>");
						var pageDom = $(".pagination");
						pageDom.empty();
						pageTotal = data.totlePage;
						page.creatPageHTML(pageNum, pageTotal, pageDom, "chooseUserType");
						/*--------------------------------------跳转页-------------------------------------------------------*/
						$(".pageGoBtn").click(function() {
							var pageNum = 0;
							pageNum = $(".pageGoText").val();
							if (pageNum > pageTotal) {
								pageNum = pageTotal;
							} else if (pageNum < 1) {
								pageNum = 1;
							}
							chooseUserType(pageNum);
						});
					}
				}
			});
		};
	</script>
</body>
</html>
